package com.magicsoft.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.magicsoft.app.entity.BonusEntity;

public class BonusRecordAdapter extends BaseAdapter{
	LayoutInflater inflater;
	List<BonusEntity> data;
	String type;
	
	public BonusRecordAdapter(Context context, List<BonusEntity> data, String type) {
		inflater = LayoutInflater.from(context);
		this.data = data;
		this.type = type;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_bonus_record, null);
			holder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
			holder.tvIncrease = (TextView) convertView.findViewById(R.id.tv_increase);
			holder.tvDecrease = (TextView) convertView.findViewById(R.id.tv_decrease);
			holder.tvTotalBonus = (TextView) convertView.findViewById(R.id.tv_total_bonus);
			holder.tvIncreaseTitle = (TextView) convertView.findViewById(R.id.tv_increase_title);
			holder.llTotalBonus = (LinearLayout) convertView.findViewById(R.id.ll_total_bonus);
			holder.llDecrease = (LinearLayout) convertView.findViewById(R.id.ll_decrease);
			
			holder.tvIncreaseTitle.setText("奖金包：");
			holder.llTotalBonus.setVisibility(View.GONE);
			holder.llDecrease.setVisibility(View.GONE);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		BonusEntity entity = data.get(position);
		String date = entity.getDate();
		String increase = entity.getIncrease();

		holder.tvDate.setText(date);
		holder.tvIncrease.setText(increase);

		if ("team".equals(type)) {
			// 集体
			holder.tvIncreaseTitle.setText("奖励：");
			holder.llTotalBonus.setVisibility(View.VISIBLE);
			holder.llDecrease.setVisibility(View.VISIBLE);
			
			String totalBonus = entity.getTotalBonus();
			String decrease = entity.getDecrease();
			
			holder.tvDecrease.setText(decrease);
			holder.tvTotalBonus.setText(totalBonus);
		} else {
			// 个人
			holder.tvIncreaseTitle.setText("奖金包：");
			holder.llTotalBonus.setVisibility(View.GONE);
			holder.llDecrease.setVisibility(View.GONE);
		}
		
		return convertView;
	}

	private static final class ViewHolder {
		TextView tvDate;
		TextView tvIncrease;
		TextView tvDecrease;
		TextView tvTotalBonus;
		TextView tvIncreaseTitle;
		LinearLayout llTotalBonus;
		LinearLayout llDecrease;
	}
}
